package com.bm.specialvehiclefordispatcher.activity.welcome;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.bm.specialvehiclefordispatcher.R;
import com.bm.specialvehiclefordispatcher.activity.BaseActivity;
import com.bm.specialvehiclefordispatcher.activity.main.MainActivity;

public class GuidancePagerActivity extends BaseActivity {

	private ViewPager mviewpager;

	private ImageView enter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_guidance_pager);
		findViews();
		init();
		addListeners();

	}

	/**
	 * 初始化控件
	 */
	@Override
	public void findViews() {
		mviewpager = (ViewPager) findViewById(R.id.whatsnew_viewpager);
	}

	/**
	 * 初始化数据
	 */
	@SuppressLint("InflateParams")
	@Override
	public void init() {
		LayoutInflater inflater = LayoutInflater.from(this);
		View view1 = inflater.inflate(R.layout.welcome_pager_one, null);
		View view2 = inflater.inflate(R.layout.welcome_pager_two, null);
		View view3 = inflater.inflate(R.layout.welcome_pager_three, null);
		
		enter = (ImageView) view3.findViewById(R.id.enter);
		
		enter.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(GuidancePagerActivity.this, MainActivity.class);
				startActivity(intent);
				finish();
			}
		});
		final ArrayList<View> views = new ArrayList<View>();
		views.add(view1);
		views.add(view2);
		views.add(view3);
		// ViewPager 适配器
		PagerAdapter mPagerAdapter = new PagerAdapter() {

			@Override
			public boolean isViewFromObject(View arg0, Object arg1) {
				return arg0 == arg1;
			}

			@Override
			public int getCount() {
				return views.size();
			}

			@Override
			public void destroyItem(View container, int position, Object object) {
				((ViewPager) container).removeView(views.get(position));
			}

			@Override
			public Object instantiateItem(View container, int position) {
				((ViewPager) container).addView(views.get(position));
				return views.get(position);
			}

		};

		mviewpager.setAdapter(mPagerAdapter);
	}

	/**
	 * 事件监听
	 */
	@Override
	public void addListeners() {
		// guidance_btn.setOnClickListener(new OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		// Intent intent = new Intent(GuidancePagerActivity.this,
		// MainActivity.class);
		// startActivity(intent);
		// finish();
		// }
		// });
		// mviewpager.setOnPageChangeListener(new MyOnPagechangeListener());
	}

}
